package com.ruoyi.system.controller;

import java.io.InputStream;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.aliyun.AliyunOSSUtils;
import com.ruoyi.system.domain.FinanceMember;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.FinanceRecharge;
import com.ruoyi.system.service.IFinanceRechargeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 重置订单管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/recharge")
public class FinanceRechargeController extends BaseController
{
    @Autowired
    private IFinanceRechargeService financeRechargeService;

    @Autowired
    private AliyunOSSUtils aliyunOSSUtils;

    /**
     * 查询重置订单管理列表
     */
    @RequiresPermissions("finance_recharge:recharge:list")
    @GetMapping("/list")
    public TableDataInfo list(FinanceRecharge financeRecharge)
    {
        startPage();
        List<FinanceRecharge> list = financeRechargeService.selectFinanceRechargeList(financeRecharge);
        return getDataTable(list);
    }

    /**
     * 导出重置订单管理列表
     */
    @RequiresPermissions("finance_recharge:recharge:export")
    @Log(title = "重置订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FinanceRecharge financeRecharge)
    {
        List<FinanceRecharge> list = financeRechargeService.selectFinanceRechargeList(financeRecharge);
        ExcelUtil<FinanceRecharge> util = new ExcelUtil<FinanceRecharge>(FinanceRecharge.class);
        util.exportExcel(response, list, "重置订单管理数据");
    }

    /**
     * 获取重置订单管理详细信息
     */
    @RequiresPermissions("finance_recharge:recharge:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(financeRechargeService.selectFinanceRechargeById(id));
    }

    /**
     * 新增重置订单管理
     */
    @RequiresPermissions("finance_recharge:recharge:add")
    @Log(title = "重置订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FinanceRecharge financeRecharge)
    {
        return toAjax(financeRechargeService.insertFinanceRecharge(financeRecharge));
    }

    /**
     * 修改重置订单管理
     */
    @RequiresPermissions("finance_recharge:recharge:edit")
    @Log(title = "重置订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FinanceRecharge financeRecharge)
    {
        return toAjax(financeRechargeService.updateFinanceRecharge(financeRecharge));
    }

    /**
     * 删除重置订单管理
     */
    @RequiresPermissions("finance_recharge:recharge:remove")
    @Log(title = "重置订单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(financeRechargeService.deleteFinanceRechargeByIds(ids));
    }

    /**
     * 导入会员订单管理数据
     */
    @RequiresPermissions("finance_recharge:recharge:import")
    @Log(title = "会员订单管理", businessType = BusinessType.IMPORT)
    @PostMapping("/import")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException
    {
        ExcelUtil<FinanceRecharge> util = new ExcelUtil<FinanceRecharge>(FinanceRecharge.class);
        List<FinanceRecharge> financeMemberList = util.importExcel(file.getInputStream());
        financeRechargeService.importFinanceMember(financeMemberList);
        return success();
    }

    //图片上传下载
    @RequestMapping("fileUpload")
    public String upload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        InputStream inputStream = file.getInputStream();
        String s = aliyunOSSUtils.putObject(inputStream, originalFilename);
        return s;
    }

    /**
     * 详情
     */
//    @RequiresPermissions("finance_recharge:recharge:query")
//    @PostMapping("/{id}/detail")
//    public AjaxResult getIn(@PathVariable("id") Long id) {
//        // 调用服务层方法查询指定ID的财务充值信息
//        FinanceRecharge financeRecharge = financeRechargeService.selectFinanceRechargeById(id);
//        // 封装成功响应结果并返回
//        return success(financeRecharge);
//    }
}
